//package com.rxyb.auth.handler;
//
//import com.rxyb.auth.feign.user.UserFeignServer;
//import com.rxyb.auth.pojo.user.AuthorityRoleVo;
//import com.rxyb.auth.pojo.user.GetRoleListReq;
//import com.rxyb.auth.pojo.user.GetRoleListRsp;
//import com.rxyb.core.respone.R;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.access.ConfigAttribute;
//import org.springframework.security.access.SecurityConfig;
//import org.springframework.security.web.FilterInvocation;
//import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
//import org.springframework.stereotype.Service;
//
//import java.util.Collection;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * 从数据库中获取url对应的role信息
// *
// * @author duyh
// * @date 2020/5/23
// */
//@Service
//public class UrlRolesFilterHandler implements FilterInvocationSecurityMetadataSource {
//
//    // user信息
//    private final UserFeignServer userFeignServer;
//
//    public UrlRolesFilterHandler(UserFeignServer userFeignServer) {
//        this.userFeignServer = userFeignServer;
//    }
//
//    @Override
//    public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
//        String requestUrl = ((FilterInvocation) object).getRequestUrl();
//        List<String> roleNames = null;
//        GetRoleListReq getRoleListReq = new GetRoleListReq();
//        if ("/login".equals(requestUrl) || "/logout".equals(requestUrl)) {
//            /* 获取全部角色 */
//        } else {
//            /* 根据路径获取可以访问这些路径的角色 */
//            getRoleListReq.setMenuUrl(requestUrl);
//        }
//        final R<GetRoleListRsp> r = userFeignServer.rolelist(getRoleListReq);
//        final List<AuthorityRoleVo> list = r.getData().getList();
//        roleNames = list.stream().map(AuthorityRoleVo::getRoleId).distinct().collect(Collectors.toList());
//        String[] names = new String[roleNames.size()];
//        for (int i = 0; i < roleNames.size(); i++) {
//            names[i] = roleNames.get(i).toString();
//        }
//        return SecurityConfig.createList(names);
//    }
//
//    @Override
//    public Collection<ConfigAttribute> getAllConfigAttributes() {
//        return null;
//    }
//
//    @Override
//    public boolean supports(Class<?> aClass) {
//        return FilterInvocation.class.isAssignableFrom(aClass);
//    }
//}
